﻿using System.Threading;

namespace WholeSlideImageViewer.OptiExport
{
    internal class OptiExportProgress : IExportProgress
    {
        public event ExportProgressTileCountEstimated? TileCountEstimated;
        public event ExportProgressTileCountWritten? TileCountWritten;
        public event ExportProgressCompleted? Completed;
        public event ExportProgressFailed? Failed;
        public event ExportProgressCanceled? Canceled;

        private int _totalTileCount = 0;
        private int _tileCount = 0;

        public void NotifyTileCountEstimated(int tileCount)
        {
            _totalTileCount = tileCount;
            TileCountEstimated?.Invoke(tileCount);
        }

        public void NotifyOneTileWritten()
        {
            TileCountWritten?.Invoke(_totalTileCount, Interlocked.Increment(ref _tileCount));
        }

        public void NotifyCompleted()
        {
            Completed?.Invoke();
        }

        public void NotifyFailed()
        {
            Failed?.Invoke();
        }

        public void NotifyCanceled()
        {
            Canceled?.Invoke();
        }

    }

}
